package com.xls.pet.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.mybatisflex.annotation.*;
import com.xls.pet.listener.ItemOnSetListener;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.Date;
import java.time.LocalDateTime;

/**
 * 实体类。
 *
 * @author xls
 * @since 2024-06-17
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(value = "item", onSet = ItemOnSetListener.class)
public class Item implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    @ColumnAlias("itemId")
    @Id(keyType = KeyType.Auto)
    private Integer id;

    /**
     * 分类id
     */
    private Integer categoryId;

    /**
     * 分类名称
     */
    @Column(ignore = true)
    private String categoryName;

    /**
     * 名称
     */
    private String name;

    /**
     * 保质期
     */
    private Integer shelfLife;

    /**
     * 单位
     */
    private Integer unit;

    @Column(ignore = true)
    private String unitString;

    /**
     * 原价
     */
    @Column(ignore = true)
    private BigDecimal price;

    /**
     * 购买价格
     */
    @Column(ignore = true)
    private BigDecimal purchasePrice;

    /**
     * 数量
     */
    @Column(ignore = true)
    private Integer quantity;

    /**
     * 重量
     */
    @Column(ignore = true)
    private String weight;

    /**
     * 生产日期
     */
    @Column(ignore = true)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
    private Date productDate;

    /**
     * 图片地址
     */
    private String image;

    @ColumnAlias("itemCreateTime")
    @Column(onInsertValue = "now()")
    private LocalDateTime createTime;

    @ColumnAlias("itemUpdateTime")
    @Column(onInsertValue = "now()", onUpdateValue = "now()")
    private LocalDateTime updateTime;

}
